public class Solution69 {
    public int mySqrt(int x) {
        long l=0,r=x;
        long ans=-1;
        while (l<=r){
            long mid=(l+r)/2;
            if (mid*mid>x){
                r=mid-1;
            }else{
                ans=mid;
                l=mid+1;
            }
        }
        return (int)ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution69().mySqrt(4));
    }
}
